using Microsoft.AspNetCore.Mvc;
using BackEnd.Model;

namespace BackEnd.Controllers
{
    /// <summary>
    /// 天气预报
    /// </summary>
    [ApiController]
    [Route("[controller]/[action]")]
    public class WeatherForecastController : ControllerBase
    {
        private static readonly string[] Summaries = new[]
        {
           "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
        };

        private readonly ILogger<WeatherForecastController> _logger;

        /// <summary>
        /// DI 构造注册 _logger
        /// </summary>
        /// <param name="logger">logger</param>
        public WeatherForecastController(ILogger<WeatherForecastController> logger)
        {
            _logger = logger;
        }

        /// <summary>
        /// 查询天气预报
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IEnumerable<WeatherForecast> Get()
        {
            _logger.LogInformation("进入BackEnd.WeatherForecast.Get方法");

            return Enumerable.Range(1, 5).Select(index => new WeatherForecast
            {
                Date = DateTime.Now.AddDays(index),
                TemperatureC = Random.Shared.Next(-20, 55),
                Summary = Summaries[Random.Shared.Next(Summaries.Length)]
            }).ToArray();
        }

        //[HttpPost]
        //public ActionResult Post([FromBody] string body)
        //{
        //    _logger.LogInformation("进入BackEnd.WeatherForecast.Post方法");

        //    //var wf = System.Text.Json.JsonSerializer.Deserialize<WeatherForecast>(body);

        //    return Ok(body);

        //}


    }
}